﻿var feeds_inter;

function PageInit(){
	Nifty("div#menu","small transparent top");
	
	Nifty("#menu a","small transparent top");
	
	Nifty("div#flashcontent_outside","top bottom");
	
	Nifty("div#search","top");
	Nifty("div#Syn","top bottom");
	
	Nifty("div#PageRank","small bottom");
	Nifty("div#refer_info","tl bottom");

	Nifty("li.ComListLi,div.Form","");
	Nifty("div.ListContent","small");
	Nifty("div#content","bl");

	Nifty("div#sidebarL,div#sidebarR,div#content","same-height none");
	//$( '#top_div').hide();
	
	Nifty("#taotao span","top bottom");
	
	creatTaoTao();
}

function feeds_slideUp(){
	  $("#feeds").animate({
		  height: 'hide',
		  opacity: 'hide'
	  }, 'normal');
	clearInterval(feeds_inter); 
}

function fadeInTopmenu(){
	$("#menu_top").animate
	  (
	 	{top: "0px"}, 400, function()
			{}
	  );
}

function fadeOutTopmenu(){
	$("#menu_top").animate
	  (
		{top: "-18px"}, 400, function()
			{}
	  );
}

function doApi(E){
	if(E.ret==0&&E.posts){
		var C=E.posts[0].cn;var F=E.posts[0].time.split(",");
		var A=["","秒钟前","分钟前","小时前","天前"];
		var B=F[1];var D=A[F[0]]||"";B+=D;
		taotao_str = '<a target="_blank" href="http://www.taotao.com/v1/space/'+E.ui.qq+'"><span title="'+B+' 在滔滔上说到">'+C+"</span></a>";
		$("#taotao").html(taotao_str);
		if(_.title.indexOf("-")>0){_.title=_.title.split("-")[0]+"- "+C}}else{$("#taotao").html("<span>该号码没有滔滔数据。</span>");
	}
}

function creatTaoTao(){
	uin=417216433;
	var A=document.createElement("script");
	A.type="text/javascript";
	A.charset="utf-8";
	A.src="http://www.taotao.com/cgi-bin/msgj?qq="+uin+"&num=1&t=0&"+Math.random();
	document.body.appendChild(A);
}

function animateIn(callback){
	$("#sidebarR").show('fast');
	$("#sidebarL").show('fast');

	$("#sidebarR").animate
	  (
	 	{right: "-1px"}, 400, function()
			{
				$("#sidebarL").animate
				  (
					{right: "105px"}, 400, function()
						{
							if(callback) callback();
						}
				  );
			}
	  );
}

function animateOut(callback){
	$("#sidebarL").animate
	  (
		{right: "-220px"}, 400, function()
			{
				$("#sidebarR").animate
				  (
					{right: "-220px"}, 400, function()
						{
							if(callback) callback();
						}
				  );
			}
	  );
}

function getImgpath(object, type){
	img_path = $(object).attr('src');
	img_path_list = img_path.split('/');
	img_path_name = img_path_list[img_path_list.length-1];
	img_path_name_prefix = img_path_name.substring(0,img_path_name.length-4);
	if(type==1) img_path = img_path.replace(img_path_name_prefix,img_path_name_prefix+'_a');
	if(type==2) img_path = img_path.replace(img_path_name_prefix,img_path_name_prefix.substring(0,img_path_name_prefix.length-2));
	return img_path
}

function Clickbilding(){
	$("#menu_top_middle img").each(
		function(intIndex){
			$(this).hover(
				function(){
					$(this).attr('src',getImgpath(this,1));
				},function(){
					$(this).attr('src',getImgpath(this,2));
				}
			 );
		}
	)
	
	$("#i_close_sidebar").toggle(
		function(){
			$(this).attr('title','显示侧边栏');
			animateOut(function(){
				$("#SC").animate({marginRight:"0px"},"fast");
			})},
		function(){
			$(this).attr('title','隐藏侧边栏');
			animateIn(function(){
				$("#SC").animate({marginRight:"300px"},"fast"); 
			})}
	);

	$("#menu_top").hover(
		function() {
			fadeInTopmenu();
		},function(){}
	 ); 

	$("#i_close_toolbar").click(
		function(){
			$(this).attr('title','显示工具栏');
			fadeOutTopmenu();
		}
	);
	
	$("[name='custom_cartoon']").click(function(e){
		animateOut(function(){
			fadeOutTopmenu();
			window.location=e.target;
		});								
		return false;
	});

	$( '#top_div' ).scrollFollow(
		{
			//container: 'module'		
			 speed: 1500,
			 offset: 300,
			 relativeTo:'bottom',
			 delay:0
		}
	);
	
	$("#Syn").hover(
		function() {
			clearInterval(feeds_inter);
			if($("#feeds").is(":visible")==false){
				//$("#feeds").slideDown('slow');
				//$("#feeds").fadeIn("slow");
				
        $("#feeds").animate({
            height: 'show',
            opacity: 'show'
        }, 'slow');

			};
		}, 
		function() {
			if($("#feeds").is(":visible")){
				feeds_inter=setInterval(feeds_slideUp,2000);
			};
		}
	 );

	$("#Qme").hover(
		function() {
			$(this).css('backgroundPosition', '0px -211px');
		},
		function() {
			$(this).css('backgroundPosition', '0px -208px');
		}
	 );

	$("#Mme").hover(
		function() {
			$(this).css('backgroundPosition', '-50px -211px');
		},
		function() {
			$(this).css('backgroundPosition', '-50px -208px');
		}
	 );

}

$(document).ready(function(){
	PageInit();
	
	animateIn(fadeInTopmenu);
	
	Clickbilding();
}); 
